var $fnzTree;
function loadTreeObj(terNodes, selTypeIds){
  	var tempTreeAy = eval(terNodes);
	treeNodes = tempTreeAy;
	initTreeForCheckBox(treeNodes, false, selTypeIds);
}
function initTreeForCheckBox(nodes, isOpenAll, selTypeIds){
	var setting = {
			check: {
				enable: true,
				chkStyle: "checkbox",
				chkboxType: { "Y": "ps", "N": "ps" }
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId",
					rootPId: 0
				}
			},
			callback: {
				onCheck: zTreeOnCheck,
				onExpand: zTreeOnExpand,
				onCollapse: zTreeOnCollapse
			}
		};
	tree = $.fn.zTree.init($("#tree"), setting, nodes);
	$fnzTree = $.fn.zTree;
	if(!isOpenAll){
		tree.expandAll(isOpenAll);
	}
	if(selTypeIds.length>0){
		var ids= new Array;
		ids = selTypeIds.split(",");
		for(var i=0;i<ids.length;i++){
			var node=tree.getNodeByParam("id", ids[i], null);
			tree.expandNode(node, true, false,true);
			tree.checkNode(node,true,false) ;
		}
		
	}
};	
function zTreeOnExpand(event, treeId, treeNode) {
    tree.expandNode(treeNode, true, false);
};
function zTreeOnCollapse(event, treeId, treeNode) {
    tree.expandNode(treeNode, false, true);
};
function zTreeOnCheck(event, treeId, treeNode) {
};
function zTreeBeforeCheck(treeId, treeNode) {
	return !treeNode.isParent;
}

function getSelTypeIds(){
	var treeObj = $.fn.zTree.getZTreeObj("tree");
	var nodes = treeObj.getCheckedNodes(true);
	var ids='';
	for(var i=0;i<nodes.length;i++){
		if(i==0){
			ids=nodes[i].id;
		}
		else{
			ids=ids+','+nodes[i].id;
		}
	}
	if(parent._chooseGoodsTypeCallback && typeof(parent._chooseGoodsTypeCallback)=='function'){
	    	parent._chooseGoodsTypeCallback(ids);
	  }
};
